#include "BaseType.h"
#include "SectionBasic.h"
#include <stdlib.h>
#include <assert.h>

static const int DIM = 2;

SectionBasic* section_basic_create(FType grade, FType h)
{
	SectionBasic* basic = (SectionBasic*)malloc(sizeof(SectionBasic));
	assert(basic);
	basic->mat = matrix_clone(get_eye2x2());
	section_basic_set_x_grade(basic, grade);
	basic->origin.v[0] = 0;
	basic->origin.v[1] = h;
	return basic;
}

SectionBasic* section_basic_free(SectionBasic* basic)
{
	if (basic) {
		free(basic->mat);
		free(basic);
	}
	return NULL;
}

SectionBasic* section_basic_set_x_grade(SectionBasic* basic, FType grade)
{
	assert(basic);
	matrix_set(basic->mat, 0, 1, grade);
	return basic;
}

Matrix* section_transform(SectionBasic* basic, Matrix* from_points)
{
	assert(basic);
	assert(from_points);
	Matrix* to_points = matrix_create(from_points->m, from_points->n);
	assert(to_points);
	matrix_mul(from_points, basic->mat, to_points);
	matrix_translation(to_points, basic->origin.v, DIM);
	return to_points;
}

/**

 *
 */